package com.pzhu.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pzhu.dormitory.dao.AdDao;
import com.pzhu.dormitory.entity.AdEntity;
import com.pzhu.dormitory.entity.MenuEntity;
import com.pzhu.dormitory.service.AdService;
import com.pzhu.dormitory.utils.PageUtils;
import com.pzhu.dormitory.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("adService")
public class AdServiceImpl extends ServiceImpl<AdDao, AdEntity> implements AdService {

    @Override
    public PageUtils<AdEntity> queryPage(Map<String, Object> params) {
        String title = (String) params.get("title");
        QueryWrapper<AdEntity> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(title)) {
            queryWrapper.lambda().like(AdEntity::getTitle, "%" + title + "%");
        }
        IPage<AdEntity> page = this.page(
                new Query<AdEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils<>(page);
    }

}
